function createFly() {
  if (mpvuePlatform === 'wx') {
    const Fly = require('flyio/dist/npm/wx');
    return new Fly();
  }
  return null;
}

export  function get(url, params = {}) {
  const Fly = createFly();
  if (Fly) {
    return new Promise(function (resolve, reject) {
      Fly.get(url, params).then((response) => {
        if (response && response.data && response.data.error_code===0) {
          resolve(response);
        }else{
          const msg = response && response.data && response.data.msg || '请求失败';
          mpvue.showToast({
            title : msg,
            duration : 2000,
          });
          reject(response);
        }
      }).catch(err => {
        reject(err);
      })
    })
  }
}

export  function post(url, params = {}) {
  const Fly = createFly();
  if (Fly) {
    return new Promise(function (resolve, reject) {
      Fly.post(url, params).then((response) => {
        if (response && response.data && response.data.error_code===0) {
          resolve(response);
        }else{
          const msg = response && response.data && response.data.msg || '请求失败';
          mpvue.showToast({
            title : msg,
            duration : 2000,
          });
        }
      }).catch(err => {
        reject(err);
      })
    })
  }
}

